package components.tools.photos
{
	import SEApp.boxes.albums.se_previewItem;
	
	import UIFree.ObjectEvent;
	import UIFree.uif_component;
	
	import components.clt_component;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class clt_photosLayer extends clt_component {
		private var _albums: clt_albums;
		public function clt_photosLayer(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			clt.externalServer.getAlbums(clt.externalServer.viewer_id, function(a_data: Object): void {
				if (a_data && (a_data is Array) && ((a_data as Array).length > 0)) {
					var filterAlbums: Array = clt.filterAlbums(a_data as Array);
					if (filterAlbums.length > 0) {
						var inner: Rectangle = getInner();
						_albums = new clt_albums(This, clt.externalServer.viewer_id, filterAlbums, Math.round(inner.width / 100), 
								true, inner.x, inner.y, inner.width, inner.height, 0, 'tabBox');
						_albums.addEvent(Event.SELECT, doAlbumPhotoSelect);
					}
				}  
			});
		}
		
		protected function doAlbumPhotoSelect(e: ObjectEvent): void {
			var item	: se_previewItem = e.object as se_previewItem;
			var a_data	: Object = item.data;
			var imageURL: String = a_data.pic_big?a_data.pic_big:
									a_data.src_big?a_data.src_big:
									a_data.src
			if (!item.image.source.bitmapContentAccess)
				imageURL = clt_servers.GETIMAGEURL + imageURL;
			workspace.loadPhoto(imageURL);
		}
	}
}